import { homeCategoryHead } from '@/api/category'
const state = {
  // 类目列表
  list: [
    { name: '居家', id: '1' },
    { name: '美食', id: '2' },
    { name: '服饰', id: '3' },
    { name: '母婴', id: '4' },
    { name: '个护', id: '5' },
    { name: '严选', id: '6' },
    { name: '数码', id: '7' },
    { name: '运动', id: '8' },
    { name: '杂项', id: '9' }
  ]
}
const mutations = {
  setList (state, value) {
    state.list = value
  },
  // 显示下拉框
  show (state, value) {
    const _temp = state.list.find(item => item.id === value.id)
    if (_temp) {
      _temp.open = true
    }
  },
  // 隐藏下拉框
  hide (state, value) {
    const _temp = state.list.find(item => item.id === value.id)
    if (_temp) {
      _temp.open = false
    }
  }
}
const actions = {
  async getList ({ commit }) {
    const res = await homeCategoryHead()
    res.result.forEach(item => {
      item.open = false
    })
    commit('setList', res.result)
    console.log(res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
